package com.ultra.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.ultra.R;
import com.ultra.model.SysModule;
import com.ultra.util.ImgUtil;

public class MenuAdapter extends BaseAdapter {
		private Context context;
		private ArrayList<SysModule> sysModuleList;
		public MenuAdapter(Context context,ArrayList<SysModule> sysModuleList) {
			this.context = context;
			this.sysModuleList = sysModuleList;
		}
		
		public int getCount() {
			return sysModuleList.size();
		}

		public Object getItem(int position) {
			return sysModuleList.get(position);
		}

		public long getItemId(int position) {
			return position;
		}

		public View getView(int position, View convertView, ViewGroup parent) {
			ViewHolder holder = null;
			if (convertView == null) {
				convertView = LayoutInflater.from(context).inflate(R.layout.adapter_menu,null);
				holder = new ViewHolder();
				holder.img = (ImageView) convertView
						.findViewById(R.id.adapter_menu_img);
				holder.text = (TextView) convertView
						.findViewById(R.id.adapter_menu_text);
//				holder.num = (TextView) convertView
//						.findViewById(R.id.desktop_list_point);
//				
				convertView.setTag(holder);
				
			} else {
				holder = (ViewHolder) convertView.getTag();
			}
			
			holder.img.setImageDrawable(ImgUtil.getImgDrawable(ImgUtil.IC,sysModuleList.get(position).getImageUrl()));
			holder.text.setText(sysModuleList.get(position).getModuleNameCn());
			
			return convertView;
		}

		class ViewHolder {
			ImageView img;
			TextView text;
			//TextView num;
		}
	}